package com.lqk.demo.pessimisticlock.reentrantLock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author lqk
 * @date 2021/12/22 20:43
 */
@Slf4j
public class ReentrantLock1 {
    /**
     * ReentrantLock:
     *  可重入特性
     */
    private static ReentrantLock lock = new ReentrantLock();
    public static void main(String[] args) {
        lock.lock();
        try{
            log.debug("enter main");
            m1();
        }finally {
            lock.unlock();
        }
    }

    public static void m1(){
        lock.lock();
        try{
            log.debug("enter m1");
            m2();
        }finally {
            lock.unlock();
        }
    }

    public static void m2(){
        lock.lock();
        try{
            log.debug("enter m2");
        }finally {
            lock.unlock();
        }
    }
}
